package top.ffhome.concurrency.example.syncContainer;

import lombok.extern.slf4j.Slf4j;
import top.ffhome.common.annotation.NotThreadSafe;

import java.util.Vector;

@Slf4j
@NotThreadSafe
public class VectorExample2 {
    private static Vector<Integer> vector = new Vector<>();
    // 请求总数
    public static int clientTotal = 5000;
    // 同时并发执行的线程数
    public static int threadTotal = 200;

    public static void main(String[] args) throws InterruptedException {
        while (true) {
            for (int i = 0; i < 10; i++) {
                vector.add(i);
            }

            Thread thread1 = new Thread(() -> {
                for (int i = 0; i < vector.size(); i++) {
                    vector.remove(i);
                }
            });

            Thread thread2 = new Thread(() -> {
                for (int i = 0; i < vector.size(); i++) {
                    vector.get(i);
                }
            });

            thread1.start();
            thread2.start();
        }
    }
}
